class Queue:
    def __init__(self, max_size):
        # self._list = [0 for i in range(max_size)]
        self._list = [0] * max_size
        self._front = 0
        self._rear = 0

    def is_empty(self):
        """
        判断队列是否为空
        :return:
        """
        return self._rear == self._front

    def is_full(self):
        """
        判断队列是否已满
        :return:
        """
        return self._next_index(self._rear) == self._front

    def __len__(self):
        return self._rear - self._front

    def append(self, element):
        if self.is_full():
            raise Exception("queue is full")
        self._rear = self._next_index(self._rear)
        self._list[self._rear] = element

    def pop_left(self):
        if self.is_empty():
            raise Exception("queue is empty")
        element = self._list[self._front]
        self._front = self._next_index(self._front)
        return element

    def get_first(self):
        return self._list[self._front]

    def get_last(self):
        return self._list[self._rear]

    def _next_index(self, start_index):
        return (start_index + 1) % (len(self._list))
